package com.thinvent.smart.chain.controller;

import com.alipay.mychain.sdk.message.transaction.contract.CallContractResponse;
import com.alipay.mychain.sdk.utils.ByteUtils;
import com.alipay.mychain.sdk.vm.EVMOutput;
import com.thinvent.smart.chain.contract.AntChainDemo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RequestMapping("/ant")
@RestController
public class AntChainController {

    @RequestMapping("/test")
    public String  antChainDemo() throws IOException {
        CallContractResponse callContractResponse = AntChainDemo.callContractDemo();
        byte[] output = callContractResponse.getTransactionReceipt().getOutput();
        EVMOutput contractReturnValues = new EVMOutput(ByteUtils.toHexString(output));
        String string = contractReturnValues.getString();
        return string;
    }

}
